package News.dao;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import News.entity.NewsUser;
import News.util.DBUtil;

public class UserDao {
	public NewsUser login(String u, String p) {
		String sql = "select * from news_users where uname=? and upwd=?";
		Connection con = DBUtil.getConnection();
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {
			ps = con.prepareStatement(sql);
			ps.setString(1, u);
			ps.setString(2, p);
			rs = ps.executeQuery();
			if (rs.next()) {
				NewsUser st = new NewsUser();
				st.setUname(rs.getString("uname"));
				st.setUpwd(rs.getString("upwd"));
				return st;
			}
		} catch (SQLException e) {
			e.printStackTrace();
		} finally {
			DBUtil.close(rs, ps, con);
		}
		return null;

	}
}
